package com.itic.mall.system.ywym.goods.service;

import com.itic.appbase.framework.common.constants.DBConst;
import com.itic.appbase.framework.common.service.CrudService;
import com.itic.appbase.framework.utils.StringHelper;
import com.itic.mall.system.inter.ywym.goods.persistence.dao.YwymGoodsDao;
import com.itic.mall.system.inter.ywym.goods.persistence.model.YwymGoods;
import com.itic.mall.system.inter.ywym.goods.persistence.model.YwymGoodsExample;
import com.itic.mall.system.inter.ywym.goods.persistence.model.YwymGoodsExample.Criteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
public class YwymGoodsService
     extends CrudService<YwymGoodsDao,YwymGoods,YwymGoodsExample> {
    @Autowired
    private YwymGoodsDao ywymGoodsDao;
    /**
     * 根据设备编号获取关联的商品编号列表
     * @param userId
     * @return
     */
    public List<String> getYwymGoodsList(String userId){
    	List<String> list = new ArrayList<String>();
    	if(StringHelper.isNotBlank(userId)){
    		YwymGoodsExample example = new YwymGoodsExample();
    		Criteria criteria = example.createCriteria();
    		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    		criteria.andUserIdEqualTo(userId);
    		List<YwymGoods> goodsList = this.ywymGoodsDao.selectByExample(example);
    		for(YwymGoods temp:goodsList){
    			list.add(temp.getSpuId());
    		}
    	}
    	return list;
    }
    /**
     * 根据设备编号获取商品信息
     * @param userId
     * @return
     */
    public List<YwymGoods> getYwymGoods(String userId){
    	List<YwymGoods> list = null;
    	if(StringHelper.isNotBlank(userId)){
    		YwymGoodsExample example = new YwymGoodsExample();
    		Criteria criteria = example.createCriteria();
    		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    		criteria.andUserIdEqualTo(userId);
    		list = this.ywymGoodsDao.selectByExample(example);
    	}
    	return list;
    }
}